package com.tencreat.mall.controller.app;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.utils.SecurityUtils;
import com.tencreat.domain.mall.MallMessageRecord;
import com.tencreat.domain.mall.dto.MallMessageApiRecordDTO;
import com.tencreat.domain.mall.vo.MallMessageListVO;
import com.tencreat.service.mall.IMallMessageRecordService;
import com.tencreat.service.mall.IMallMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 联系客服
 * @author zixin
 */
@RequestMapping("/api/mall/message")
@RestController
@Api(tags = "99-联系客服")
public class MallMessageApiController {

    @Autowired
    private IMallMessageService messageService;


    @ApiOperation("获取聊天消息记录")
    @PostMapping("/record")
    HttpResult<Page<MallMessageRecord>> record(@RequestBody @Validated MallMessageApiRecordDTO vo) {
        Page<MallMessageRecord> page = new Page(vo.getCurrent(), vo.getSize());
        page = messageService.appMessage(page,vo.getUuid());
        return HttpResult.ok(page);
    }

    @ApiOperation("清除未读消息")
    @GetMapping("/clear-unread")
    HttpResult clearUnread() {
        messageService.clearAppUnreadMessage();
        return HttpResult.ok();
    }

    @ApiOperation("获取未读消息")
    @GetMapping("/unread")
    HttpResult<Integer> unread() {
        return HttpResult.ok(messageService.getAppUnreadMessage());
    }

    @ApiOperation("获取聊天列表")
    @GetMapping("/appGetMessageList")
    HttpResult<List<MallMessageListVO>> appGetMessageList() {
        List<MallMessageListVO> mallMessageListVOS = messageService.listByUserId(SecurityUtils.getLoginUser().getAccountLogin().getUuid());

        return HttpResult.ok(mallMessageListVOS);
    }
}
